package com.inspection.support;

import com.lowagie.text.Font;
import com.lowagie.text.pdf.BaseFont;
import fr.opensagres.xdocreport.itext.extension.font.IFontProvider;
import fr.opensagres.xdocreport.itext.extension.font.ITextFontRegistry;

import java.awt.*;

/**
 * pdf 字体库扩展
 * @author liukaiyang
 * @date 2018/3/19 16:00
 */
public class ExtFontProvider implements IFontProvider{
    @Override
    public Font getFont(String familyName, String encoding, float size, int style, Color color) {
        try {
            BaseFont bfChinese = BaseFont.createFont("song.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            //宋体,国标-水平(horizontal),非内置
//            BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            Font fontChinese = new Font(bfChinese, size, style, color);
            fontChinese.setFamily("SimSun");
            return fontChinese;
        } catch (Exception e) {
            e.printStackTrace();
            return ITextFontRegistry.getRegistry().getFont(familyName, encoding, size, style, color);
        }
    }
}
